import { request } from '@/service/request';

// =============== Position Begin ===============

/** get position page list */
export function fetchGetPositionPageList(params?: Api.SystemManage.PositionSearchParams) {
  return request<Api.SystemManage.PositionPageList>({
    url: '/sys_position/page',
    method: 'GET',
    params
  });
}

/** add position info */
export function fetchAddPosition(data: Api.SystemManage.PositionEdit) {
  return request<boolean>({
    url: '/sys_position/',
    method: 'POST',
    data
  });
}

/** update position info */
export function fetchUpdatePosition(data: Api.SystemManage.PositionEdit) {
  return request<boolean>({
    url: '/sys_position/',
    method: 'PUT',
    data
  });
}

/** edit delete position */
export function fetchDeletePosition(data: Api.Common.DeleteParams) {
  return request<boolean>({
    url: '/sys_position/',
    method: 'DELETE',
    data
  });
}

/**
 * get all positions
 *
 * these positions are all enabled
 */
export function fetchGetAllPositions(orgId: string) {
  return request<CommonType.Option<string>[]>({
    url: `/sys_position/list_option_by_org_id/${orgId}`,
    method: 'GET'
  });
}

// =============== Position End  ===============

// -------------- PositionOrg --------------

export function fetchGetPositionOrgIds(positionId: string) {
  return request<string[]>({
    url: `/sys_position_org/org/${positionId}`,
    method: 'GET'
  });
}

export function fetchAddPositionOrg(data: Api.SystemManage.PositionOrg) {
  return request<boolean>({
    url: '/sys_position_org/',
    method: 'POST',
    data
  });
}
